<?php
/**连接数据库
 * @return mysqli|string
 */
session_start();
@header("content-Type: text/html; charset=utf-8");
function mylink(){
    $host = '127.0.0.1';
    $name = 'root';
    $pass = 'root';
    $data = 'mybase';
    $mylinks = mysqli_connect($host,$name,$pass,$data);
    if($mylinks){
        return $mylinks;
    }else{
        return mysqli_connect_error();
    }

}


/**查询二维数据
 * @param $sql
 * @return array|mysqli|string
 */
function query($sql){
    $mylink = mylink();
    if ($mylink){
        $arr = [];
        $res = mysqli_query($mylink,$sql);
        while ($date = mysqli_fetch_assoc($res)){
            $arr[] = $date;
        }
        return $arr;
    }else{
        return $mylink;
    }
}

/**查询一维数据
 *
 */
function lin($sql){
    $mylink = mylink();
    $res = mysqli_query($mylink,$sql);
    if (!is_bool($res)) {
        $date = mysqli_fetch_assoc($res);
        return $date;
    }
}

/**增加  删除 更新
 * @param $sql
 * @return bool|mysqli|mysqli_result|string
 */
function ints($sql){
    $aa = mylink();
    if ($aa){
        $res = mysqli_query($aa,$sql);
        return $res;
    }else{
        return $aa;
    }
}

/**跳转封装
 *
 */
function jumps($dum,$num,$url){
    echo '<script type="text/javascript">';
    echo 'alert("'.$dum.'")';
    echo '</script>';
    header('Refresh: '.$num.'; url='.$url.'');
    exit;
}

































